home *** CD-ROM | disk | FTP | other *** search
- /* JavaScript for Talk-n-Mail
- Copyright (c) 1999-2001, SoftApproach Corp. All rights reserved
- */
-
- // Sound/Music information array
- // [0] is for main sound (speech)
- var iarMusic
-
- /* Data object for a Div */
- function fobjMusicMakeDataObject()
- {
- // Embedded sound
- this.objEmbed = 0
- this.lLength = 0
- return this
- }
-
- // Make a blank array
- function faryMusicMakeArray(aiUBound)
- {
- for (var i = 0; i <= aiUBound; i++)
- {
- this[i] = new fobjMusicMakeDataObject()
- }
-
- // Number of music
- this.iiMusicCount = 0
-
- // Times to repeat for all music
- this.ilMusicPlayCount = 0
-
- // Pick up the next one randomly?
- this.ibMusicPlayRandom = false
-
- // Current music index
- this.iiMusicIndex = 0
-
- // The current Mouse Click sound
- this.divAniSound = ''
-
- // Total numbers of music to play, countdown
- this.llMusicPlayCountDown = 0
-
- // The Timeout function call id
- this.ilNextMusicId = 0
- // Turned off already?
- this.bSoundOff = false
-
-
- return this
- }
-
- // Main speech
- function fbHasSpeech(){return iarMusic[0].lLength > 0}
- // Additional music
- function fbHasMusic(){return iarMusic.iiMusicCount > 0}
-
- // Turn on the speech then play all music
- function fvPageSoundOn()
- {
-
- // Has speech?
- if(fbHasSpeech())
- iarMusic.iiMusicIndex = -1
- // No music either?
- else if(!fbHasMusic())
- {
- // Hide the buttons
- fvShow("divSound", false)
- return
- }
- else
- iarMusic.iiMusicIndex = 0
- // End if
-
- // Number of additional music to play, 0 is forever
- iarMusic.llMusicPlayCountDown = iarMusic.ilMusicPlayCount ?
- iarMusic.iiMusicCount * iarMusic.ilMusicPlayCount : 99999
-
- // To go
- iarMusic.bSoundOff = false
- fvMusicPlayOne()
- }
-
- // Get one music to play and how long it will last
- function fiGetMusic()
- {
- var liIndex = iarMusic.iiMusicIndex
-
- // Time for main speech?
- // Play once and once only
- if(liIndex == -1)
- {
- liIndex = fbHasSpeech() ? 0 : -1
- }
- // No music or total # of time finished?
- else if(!fbHasMusic() || iarMusic.llMusicPlayCountDown <= 0)
- {
- liIndex = -1
- }
- // Sequencial / one music only
- else if(!iarMusic.ibMusicPlayRandom || iarMusic.iiMusicCount == 1)
- {
- liIndex ++
- if(liIndex > iarMusic.iiMusicCount) liIndex = 1
- }
- // Random
- else
- {
- while(true)
- {
- liIndex = 1 + Math.floor(fiRandom() * iarMusic.iiMusicCount)
- if(liIndex != iarMusic.iarMusic.iiMusicIndex) break
- }
-
- }
-
- // Music picked?
- // One played
- if(liIndex > 0){iarMusic.llMusicPlayCountDown --}
-
- // Keep
- iarMusic.iiMusicIndex = liIndex
- return liIndex
- }
-
- // Called from $TNM$_Ani.js for mouse click sound
- function fvPlayMusic(divDiv)
- {
- // No more main
- fvPlayMusicEx(divDiv, true)
- }
-
- // Play one music
- function fvMusicPlayOne()
- {
- var liIndex
- var llDuration
-
- // Off but coming in again because of the timer?
- if(iarMusic.bSoundOff) return
-
- liIndex = fiGetMusic()
-
- // No more
- if(liIndex < 0) return
-
- fvPlayMusicEx(iarMusic[liIndex].objEmbed, false)
-
- // Come back again for the next one
- llDuration = iarMusic[liIndex].lLength
- iarMusic.ilNextMusicId = setTimeout('fvMusicPlayOne()', llDuration)
-
- }
- // Turn all the sound off
- function fvPageSoundOff()
- {
- // To stop
- if(iarMusic.ilNextMusicId) clearTimeout(iarMusic.ilNextMusicId)
- iarMusic.bSoundOff = true
- iarMusic.iiMusicIndex = 0
-
- if(ibIsIE)
- {
- sndBackgroundSound.src = ''
- }
- else
- {
- // Main speech / music
- if(iarMusic[iarMusic.iiMusicIndex].objEmbed)
- iarMusic[iarMusic.iiMusicIndex].objEmbed.stop()
-
- // Mouse click sound
- if(iarMusic.divAniSound) iarMusic.divAniSound.stop()
- }
- }
- function fvPlayMusicEx(divDiv, abTurnOffMain)
- {
- // Turn off the main speech/music
- if(abTurnOffMain)
- {
- fvPageSoundOff()
- }
-
- if(ibIsIE)
- {
- sndBackgroundSound.src = ''
-
- if(divDiv.src)
- sndBackgroundSound.src = divDiv.src
- else
- sndBackgroundSound.src = divDiv
- // End if
-
-
- sndBackgroundSound.volume = 0
- }
- else
- {
- divDiv.play()
- iarMusic.divAniSound = divDiv
- }
- }
-
-